import Vue from 'vue'
import Router from 'vue-router'
import {store} from '@/store/index';


Vue.use(Router);

/**
 * 基础路由
 * @type {({path: string, component: (function(): *), meta: {title: string}, name: string}|{path: string, component: (function(): *), meta: {title: string}, name: string}|{redirect: string, path: string})[]}
 */
const commonRoutes = [
  {
    path: '/login',
    name: 'login',
    meta: { title: '登录' },
    component: () => import('../components/Login.vue'),
  },
  {
    path: '/404',
    name: '404',
    meta: { title: '404' },
    component: () => import('../components/404.vue'),
  },
  { path: '/', redirect: '/home' },
];


// 本地所有的页面 需要配合后台返回的数据生成页面
export const asyncRoutes = {
  //注意  home 需要和 name中的home名称一致,必须保证
  home: {
    path: 'home',
    name: 'home',
    meta: { title: '首页' },
    component: () => import('../views/Home.vue'),
  },
  musicOnline: {
    path: 'musicOnline',
    name: 'musicOnline',
    meta: { title: '图标管理' },
    component: () => import('../views/MusicOnline.vue'),
  },
  menu: {
    path: 'menu',
    name: 'menu',
    meta: { title: '菜单管理' },
    component: () => import('../views/EditMenu.vue'),
  },
  roleAdmin: {
    path: 'roleAdmin',
    name: 'roleAdmin',
    meta: { title: '角色管理' },
    component: () => import('../views/RoleAdmin.vue'),
  },
  userInfo: {
    path: 'userInfo',
    name: 'userInfo',
    meta: { title: '用户信息' },
    component: () => import('../views/Userinfo.vue'),
  },
  blogAdmin: {
    path: 'blogAdmin',
    name: 'blogAdmin',
    meta: { title: '博客总览' },
    component: () => import('../views/BlogAdmin.vue'),
  },
  interfaceAdmin: {
    path: 'interfaceAdmin',
    name: 'interfaceAdmin',
    meta: { title: '接口管理' },
    component: () => import('../views/InterfaceAdmin.vue'),
  },
  logAdmin: {
    path: 'logAdmin',
    name: 'logAdmin',
    meta: { title: '日志管理' },
    component: () => import('../views/LogAdmin.vue'),
  },
  pictureAdmin: {
    path: 'pictureAdmin',
    name: 'pictureAdmin',
    meta: { title: '图片管理' },
    component: () => import('../views/PictureAdmin.vue'),
  },
  messageAdmin: {
    path: 'messageAdmin',
    name: 'messageAdmin',
    meta: { title: '消息管理' },
    component: () => import('../views/MessageAdmin.vue'),
  },
  sourceAdmin: {
    path: 'sourceAdmin',
    name: 'sourceAdmin',
    meta: { title: '资源管理' },
    component: () => import('../views/SourceAdmin.vue'),
  },
  monitorAdmin: {
    path: 'monitorAdmin',
    name: 'monitorAdmin',
    meta: { title: '监控管理' },
    component: () => import('../views/MonitorAdmin.vue'),
  },
  consulAdmin: {
    path: 'consulAdmin',
    name: 'consulAdmin',
    meta: { title: 'consul监控' },
    component: () => import('../views/ConsulAdmin.vue'),
  },
  blogSortAdmin: {
    path: 'blogSortAdmin',
    name: 'blogSortAdmin',
    meta: { title: '博客分类' },
    component: () => import('../views/BlogSortAdmin.vue'),
  },
  gatewayAdmin: {
    path: 'gatewayAdmin',
    name: 'gatewayAdmin',
    meta: { title: '博客分类' },
    component: () => import('../views/GatewayAdmin.vue'),
  },
  adminInfo: {
    path: 'adminInfo',
    name: 'adminInfo',
    meta: { title: '管理员详情' },
    component: () => import('../views/AdminInfo.vue'),
  },
  editPassword: {
    path: 'editPassword',
    name: 'editPassword',
    meta: { title: '修改密码' },
    component: () => import('../views/EditPassword.vue'),
  },
  blogRecommend: {
    path: 'blogRecommend',
    name: 'blogRecommend',
    meta: { title: '管理员详情' },
    component: () => import('../views/BlogRecommend.vue'),
  },
  iconAdmin: {
    path: 'iconAdmin',
    name: 'iconAdmin',
    meta: { title: '图标管理' },
    component: () => import('../views/IconAdmin.vue'),
  },
  commentAdmin: {
    path: 'commentAdmin',
    name: 'commentAdmin',
    meta: { title: '评论管理' },
    component: () => import('../views/CommentAdmin.vue'),
  },
  buttonPermission: {
    path: 'buttonPermission',
    name: 'buttonPermission',
    meta: { title: '按钮权限管理' },
    component: () => import('../views/ButtonPermission.vue'),
  },
  blogTagAdmin: {
    path: 'blogTagAdmin',
    name: 'blogTagAdmin',
    meta: { title: '标签管理' },
    component: () => import('../views/BlogTagAdmin.vue'),
  },
  
};

const createRouter = () => new Router({
  routes: commonRoutes,
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher
}
export default router
